/*
 * @Author: ZhanXie
 * @Date: 2020-08-13 15:39:24
 * @LastEditors: ZhanXie
 * @LastEditTime: 2020-09-13 21:21:31
 * @Description: 数据模型入口文件
 * @FilePath: /weibo/src/db/model/index.js
 */
const User = require('./User')
const Blog = require('./Blog')
const UserRelation = require('./UserRelation')
const AtRelation = require('./AtRelation')

Blog.belongsTo(User, {
  foreignKey: 'userId'
}) // 查微博顺带查出用户 一个用户拥有多个微博

// User.hasMany(Blog) // 查用户顺带查出微博

UserRelation.belongsTo(User, {
  foreignKey: 'followerId'
})

User.hasMany(UserRelation, {
  foreignKey: 'userId'
})

Blog.belongsTo(UserRelation, {
  foreignKey: 'userId',
  targetKey: 'followerId'
})

Blog.hasMany(AtRelation, {
  foreignKey: 'blogId'
})

module.exports = {
  User,
  Blog,
  UserRelation,
  AtRelation
}